package com.framework.core.rest;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * @author shenmengchao
 * @version 1.6.30
 * @date 2017/7/7
 * @description
 */

public class HttpUtils {

    public static final String BASE_URL = "https://api.douban.com/v2/movie/";

    private static HttpUtils mInstance;
    private OkHttpClient mOkHttpClient;
    private Retrofit mRetrofit;

    private HttpUtils(){

    }

    public static HttpUtils getInstance(){
        if(null == mInstance){
            mInstance = new HttpUtils();
        }
        return mInstance;
    }

    public void init(){
        Gson gson = new GsonBuilder()
                .registerTypeAdapterFactory(new ItemTypeAdapterFactory())
                .create();
        mOkHttpClient = new OkHttpClient();
        mRetrofit = new Retrofit.Builder()
                .baseUrl(BASE_URL)
                .addConverterFactory(GsonConverterFactory.create(gson))
                .addCallAdapterFactory(RxTransformErrorCallAdapterFactory.create())
                .build();
    }

    public Retrofit getRetrofitClient(){
        return mRetrofit;
    }

}
